<!DOCTYPE html>
<html>
  <head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>留学生管理系统</title>
        <link rel="stylesheet" href="${path}/css/admin2.css">
		<script>
            var _current_item = "#adminExamManage";
        </script>
        <script type="text/javascript" src="${path}/js/jquery.min.js"></script>
        <style>
        #set_pannal,#setOne_pannal{
                margin: 15% auto;
                padding: 10px;
                width: 400px;
            }
             #select,#select1{
            position:absolute;
    			z-index: 2000;
    			margin:-20% 0 0 0;
    			left:50%;
    			transform: translateX(-50%);
            }
            .teacher{
    			padding: 10px 30px 30px;
    			width: 900px;
    			min-height: 500px;
    			background: #fff;
			}
			.location{
    			padding: 10px 30px 30px;
    			width: 900px;
    			min-height: 500px;
    			background: #fff;
			}
            </style>
  </head>
  
  <body>
  <div class="hide">
            <!--teacher-->
            <div id="teacher" class="teacher hide pannel">
                <div class="close-container"><a class="close" onclick="hide('.teacher')">×</a></div>
                <div>
                    <span>学院</span>
                    <select onchange="lookTeacher(this.options[this.options.selectedIndex].value);" id="college">
                        <option value="全部">全部</option>
                        <#if college?exists>
                        <#list college as r> 
                        <option value="${r.collegeCode!}">${r.collegeCode!}-${r.collegeName!}</option>
                        </#list>                                             
                        </#if>	                       
                    </select>

                    <table class="ter_1" id="ter_1">
                        <thead>
                            <tr>
                                <td></td> 
                                <td>工号</td>
                                <td>姓名</td>
                                <td>学院</td> 
                                <td>职称</td>
                            </tr>
                        </thead>
                        <tbody>
                            <#if teacher?exists>
                            <#list teacher as r>
                            <tr>
                                <td><input type="checkbox" value="${r.tName}" id="teacherCheck${r_index}" name="${r.tNo}" onchange="alertTer(this)"></td>
                                <td>${r.tNo}</td>
                                <td>${r.tName}</td>
                                <td>${r.collegeName}</td>
                                <td>${r.title}</td>
                            </tr>
                            </#list>
                            </#if>
                        </tbody>
                    </table>
                    <button onclick="getTeacher(_selectteacher);hide('.teacher')">确定</button>
                </div>
            </div>
            <!--teach end-->
            <!--location-->
            <div id="location" class="location hide pannel">
                <div class="close-container"><a class="close" onclick="hide('.location');">×</a></div>
                <div class="modal-body">
                    <span>教室类型</span>
                    <select onchange="lookClassroom(this.options[this.options.selectedIndex].value);" id="classroomType" name="classroomType">
                            
                            <option value="全部">全部</option>
                             <#if classroom?exists>
                            <#list classroomType as ct>
                            <option value="${ct.classroomType}">${ct.classroomType}</option>
                            </#list>
                            </#if>
                    </select>

                    <table class="loc_1" id="examloc">
                        <thead>
                            <tr>
                                <td></td> 
                                <td>教室编号</td>
                                <td>教室容量</td>
                                <td>考试容量</td> 
                                <td>教室类型</td>
                            </tr>
                        </thead>
                        <tbody>
                            <#if classroom?exists>
                            <#list classroom as r>
                            <tr>
                                <td><input type="radio" value="${r.classroomNo}" id="classroomCheck${r_index}" name="classroomCheck" ></td>
                                <td>${r.classroomNo}</td>
                                <td>${r.classroomVolume}</td>
                                <td>${r.examVolume}</td>
                                <td>${r.classroomType}</td>
                            </tr>
                            </#list>
                            </#if>
                        </tbody>
                    </table>
                    <button onclick="getClassroom(_select + '.loc_1', _selectclassroom);hide('.location');">确定</button>
                </div>
            </div>
            <!--location end-->
            </div>
            <div id="above-mask">
            <!--  pannal -->
           	<div class="pannel hide"  id="set_pannal">
           		<div class="close-container">
                    <a class="close" onclick="$('#select').html('');hide('#mask,#above-mask,#set_pannal')">&times;</a>
                </div>
                <div>请选择统一设置：</div><br />
                <table>
                <tr><th style="width:100px"><a onclick="createDatatable('#select .ter_1');show('#select .teacher');"><b>监考老师:</b></a></th><td style="width:300px"><div id="addTer" tNo=""></div></td></tr>
                <tr><th><a  onclick="createDatatable('#select .loc_1');decorateTd('#select .loc_1');show('#select .location');"><b>考试地点:</b></a></th><td><div id="addLoc"></div></td></tr>
                <tr><th><b>考试时间:</b></th><td><input type="text" placeholder="必填"  id="addTime"class="Wdate" onClick="WdatePicker({dateFmt: 'yyyy-MM-dd HH:mm'})" required="required"></td></tr>
                </table>
                <div id="select"></div>
				<button style="margin-left:0;width:100%" id="add_conf" onclick="setTest();">确定</button>
           	</div>
           <!--  pannal end-->
           <!--  pannal one-->
           	<div class="pannel hide"  id="setOne_pannal">
           		<div class="close-container">
                    <a class="close" onclick="$('#select1').html('');hide('#mask,#above-mask,#setOne_pannal')">&times;</a>
                </div>
                <div>单条信息设置：</div><br />
                <table>
                <tr><th style="width:100px"><a onclick="createDatatable('#select1 .ter_1');show('#select1 .teacher');"><b>监考老师:</b></a></th><td style="width:300px"><div id="setTer" tNo=""></div></td></tr>
                <tr><th><a  onclick="createDatatable('#select1 .loc_1');decorateTd('#select1 .loc_1');show('#select1 .location');"><b>考试地点:</b></a></th><td><div id="setLoc"></div></td></tr>
                <tr><th><b>考试时间:</b></th><td><input type="text" placeholder="必填"  id="setTime"class="Wdate" onClick="WdatePicker({dateFmt: 'yyyy-MM-dd HH:mm'})" required="required"></td></tr>
                </table>
                <div id="select1"></div>
				<button style="margin-left:0;width:100%" id="set_conf" onclick="setOneTest();">确定</button>
           	</div>
           <!--  pannal one end-->
           </div>
           <div id="mask"></div>
  	<div id="header"></div>
    <div id="main">
        <div id="side-menu"></div>
        <div id="container">
        	<div id="inner-border">
        	 	<div class="c1">
                    <span class="c2">学期</span>
                    <select class="c5" id="termValue">
                    <option value="0">&nbsp;全部</option>
                    <#if term ?exists>
                    <#list term as t>
                    <option value=${t.termValue}>${t.termValue}</option>
                    </#list>
                    </#if>
                    </select>
                    <span>课程名</span>
                    <select class="c5" id="courseNo">
                     <option value="0">&nbsp;全部</option>
                     <#if course ??>
                     <#list course as c>
                     	<option value="${c.courseNo}">${c.courseName}</option>
                     </#list>
                     </#if>
                    </select>
                    <button type="button" style="width:80px" onclick="search()">确定</button>
                    <button type="button" style="width:80px" id="setAll">统一设置</button> 
                    <button type="button" style="width:80px" onClick="addTest()">创建补考</button> 
                 </div><br><br>
                 <div>
                    <table class="table table-bordered" id="examTab">
                      <thead>
                        <tr>
                        <th> </th>
                        <th>课程名</th> 
                        <th>教师</th>
                        <th>学期</th>
                        <th>状态</th>
                        <th>考试时间</th>
                        <th>考试地点</th>
                        <th>监考老师</th>
                        <th>操作</th>
                      	</tr>
                      </thead>
                      
                      <tbody>
                      <#if examInf ?exists>
                      <#list examInf as e>
                      <tr>
                      <td><input type="checkbox" uuid="${e.uuid}" testNo="${e.testNo}"></td>
                      <td>${e.courseName!}</td>
                      <td>${e.tName!}</td>
                      <td>${e.termValue!}</td>
                      <td>${e.testType!}</td>
                      <td>${e.test_time!}</td>
                      <td>${e.test_classroomNo!}</td>
                      <td>${e.tNames!}</td>
                      <td><button class="edit" testNo="${e.testNo}" tNo="${e.tNo}" onclick="setOne(this);">设置</button></td>

                      </tr>
                      </#list>
                      </#if>
                      </tbody>
                       
                 </table>
   		    </div><br />
   		  
    	</div>
    </div>
    </div>
    	  <div id="footer"></div>
    <script type="text/javascript" src="${path}/js/admin-main-appearance.js"></script>
    <script type="text/javascript" src="${path}/js/My97DatePicker/WdatePicker.js"></script>
    

        <!-- DataTables JavaScript -->
        <script src="${path}/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetHiddenNodes.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetTd.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetTds.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetColumnData.js"></script>
        <script src="${path}/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
    <script>
    $(document).ready(function() {
       $('#examTab').DataTable({
             responsive: true,
             ordering: false,
     		 searching: false,
            "bLengthChange": false,
            "bRetrieve": true,
            "bFilter": true//过滤功能
        });
        })
        
        
        //遍历checkbox是否选中
        
        function checked(){
        var allNodes = getAllNodes("#examTab");
        var testNo="";
        var uuid="";
    	for (var tr in allNodes)
			{
			checkbox = allNodes[tr]["cells"][0]["childNodes"][0];
        	if(checkbox["checked"] == true)
        	{testNo+=checkbox.getAttribute("testNo")+",";
        	uuid+=checkbox.getAttribute("uuid")+",";
        	//alert(uuid);
        	}
			}
			$("#add_conf").attr("testNo",testNo);
			$("#add_conf").attr("uuid",uuid);
		}
        
        //设置考试信息
        function setTest(){
        	
        	var testNo=$("#add_conf").attr("testNo");
        	var tNo=$("#addTer").attr("tNo");
        	var classroom=$("#addLoc").html();
        	var time=$("#addTime").val();
        	//alert(testNo);
        	if(testNo==""){
        	alert("请选择考试课程");
        	}else if(tNo==""||classroom==""||time==""){
        	alert("请设置完整");
        	}else{
        	
         		$.ajax({
        			type:"POST",
     				url:'${path}/adminExamManage/setTestInf',
     				dataType:"json",
     				data:{
     					testNo:testNo,
     					tNo:tNo,
     					classroom:classroom,
     					time:time,
     					},
     				success:function(data){
     				$('#select').html('');
     				hide('#mask,#above-mask,#set_pannal');
     				window.location.href = "${path}/adminExamManage/index";
     				}, 
     				error:function(err){
     				},
        			})
        	}
        }
        
        //设置单条考试信息
        function setOneTest(){
        	
        	var testNo=$("#set_conf").attr("testNo");
        	var tNo=$("#setTer").attr("tNo");//alert(tNo);
        	var classroom=$("#setLoc").html();//alert(classroom);
        	var time=$("#setTime").val();
        	//alert(testNo);
        	if(tNo==""||classroom==""||time==""){
        	alert("请设置完整");
        	}else{
        	
         		$.ajax({
        			type:"POST",
     				url:'${path}/adminExamManage/setTestInf',
     				dataType:"json",
     				data:{
     					testNo:testNo,
     					tNo:tNo,
     					classroom:classroom,
     					time:time,
     					type:"1",
     					},
     				success:function(data){
     				/* alert("sss""); */
     				 $('#select').html('');
     				hide('#mask,#above-mask,#set_pannal'); 
     				window.location.href = "${path}/adminExamManage/index";
     				}, 
     				error:function(err){},
        			})
        	}
        	
        	
        
        }
        
        //创建补考
        function addTest(){
         checked();
         var uuid=$("#add_conf").attr("uuid");
        
        $.ajax({
        type:"POST",
     	url:'${path}/adminExamManage/addTest',
     	dataType:"json",
     	data:{
     		uuid:uuid,
     	},
     	success:function(data){
     	alert(JSON.stringify(data.temp));

     	window.location.href = "${path}/adminExamManage/index";}, 
     	error:function(err){},
        })
        
        }
        
        //筛选
        function search(){
        $.ajax({
            type:"get",
                    url:'${path}/adminExamManage/termSelect',
                    data:{
                            term:$('#termValue').val(),
                            courseNo:$('#courseNo').val(),
                    },
                    datatype:"json",
                    success:function(data){
                   //alert("success");
                   alert(JSON.stringify(data));
                     $('#examTab').dataTable().fnClearTable();
                     $.each(data,function(num,data){
                     if(data.testType=="正考"){
                    	 $('#examTab').dataTable().fnAddData(['<input type="checkbox"  uuid="'+data.uuid+'" testNo="'+data.testNo+'" >',data.courseName,data.tName,data.termValue,"正考",data.test_time,data.test_classroomNo,data.tNames,'<button class="edit"  testNo="'+data.testNo+'">设置</button>']);
               			}else{
               			$('#examTab').dataTable().fnAddData(['<input type="checkbox"  uuid="'+data.uuid+'" testNo="'+data.testNo+'" >',data.courseName,data.tName,data.termValue,"补考",data.test_time,data.test_classroomNo,data.tNames,'<button class="edit"  testNo="'+data.testNo+'">设置</button>']);
               			
               			}
                     })
                
                   // getdata(data);
                    } 
            });
            }
            function lookTeacher(collegeCode) {
                                    $.ajax({
                                        async: false,
                                        type: "POST",
                                        url: "${path}/adminCourseManage/lookTeacher",
                                        dataType: "json",
                                        data: {
                                            collegeCode: collegeCode,
                                        },
                                        success: function (data) {
                                      //alert(JSON.stringify(data));
                                            $(_select + '.ter_1').dataTable().fnClearTable();
                                            for (var i = 0; i < data.length; i++) {
                                                $(_select + '.ter_1').dataTable().fnAddData(['<input id="teacherCheck0" type="checkbox" value="' + data[i]["tName"] + '" name="teacherCheck">', data[i]["tNo"], data[i]["tName"], data[i]["collegeName"], data[i]["title"]]);
                                                var ot = $(_select + '.ter_1').dataTable();
                                            }
                                        },
                                        error: function (err) {
                                            alert("获取该学院教师失败");
                                        },
                                    });
                                }
                                
                                 function lookClassroom(classroomType) {

                                    $.ajax({
                                        async: false,
                                        type: "POST",
                                        url: "${path}/adminExamManage/lookClassroom",
                                        dataType: "json",
                                        data: {
                                            classroomType: classroomType,
                                        },
                                        success: function (data) {
                                            $(_select + '.loc_1').dataTable().fnClearTable();
                                            for (var i = 0; i < data.length; i++) {
                                                $(_select + '.loc_1').dataTable().fnAddData(['<input id="classroomCheck0" type="radio" value="' + data[i]["classroomNo"] + '" name="classroomCheck">', data[i]["classroomNo"], data[i]["classroomVolume"], data[i]["examVolume"], data[i]["classroomType"]]);
                                                var ot = $(_select + '.loc_1').dataTable();
                                            }
                                            decorateTd(_select + '.loc_1');
                                        },
                                        error: function (err) {
                                            alert("获取该类型教室失败");
                                        },
                                    });
                                }
          
    </script>
    <script src="${path}/js/linkPage.js"></script>
  </body>
</html>
